package Correo;


import java.io.*;
import javax.activation.*;

/** DataSource para cualquier texto plano. */
public class SMTPByteArrayDataSource implements DataSource {

    private byte[] data;
    private String type;

    SMTPByteArrayDataSource(InputStream is, String type) {
        this.type = type;
        try {
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            int ch;
            while ((ch = is.read()) != -1) {
                os.write(ch);
            }
            data = os.toByteArray();
        } catch (IOException ioex) {
        }
    }

    SMTPByteArrayDataSource(byte[] data, String type) {
        this.data = data;
        this.type = type;
    }

    SMTPByteArrayDataSource(String data, String type) {
        this.data = data.getBytes();
        this.type = type;
    }

    public InputStream getInputStream() throws IOException {
        if (data == null) {
            throw new IOException("No hay datos");
        }
        return new ByteArrayInputStream(data);
    }

    public OutputStream getOutputStream() throws IOException {
        throw new IOException("No esta implementado");
    }

    public String getContentType() {
        return type;
    }

    public String getName() {
        return "dummy";
    }
}
